'use strict';

module.exports = app => {
  const { STRING, DATE, BIGINT } = app.Sequelize;

  const Code = app.model.define('code', {
    id: { type: BIGINT, primaryKey: true, autoIncrement: true },
    username: {
      type: STRING(50),
      allowNull: false,
    },
    code: {
      type: STRING(50), // 存储题目
      allowNull: false,
    },
    result: {
      type: BIGINT, // 存储运算结果
      allowNull: false,
    },
    expires_at: {
      type: DATE, // 过期时间，存储验证码有效期
      allowNull: false,
    },
    created_at: DATE,
    updated_at: DATE,
  }, {
    tableName: 't_code',
  });

  return Code;
};
